//
//  HJWelcomeVc.swift
//  Weibo
//
//  Created by 韩佳 on 16/4/19.
//  Copyright © 2016年 ddg. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage

class HJWelcomeVc: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }
    private func setupUI(){
        view.backgroundColor = UIColor(white: 247/255.0, alpha: 1)
        view.addSubview(headImageView)
        
        headImageView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 80, height: 80))
            make.centerX.equalTo(view)
            make.top.equalTo(200)
        }
        
        view.addSubview(messageLabel)
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView)
            make.top.equalTo(headImageView.snp_bottom).offset(15)
        }
    }
    
    //约束动画,界面显示了才能执行
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        //注意是更新约束而不是改约束
        headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(100)
        }
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(1, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        //动画结束切换控制器
//                        print("切换控制器")
                        NSNotificationCenter.defaultCenter().postNotificationName(HJChangeRootVCNotification, object: self)
                })
        }
    }
    //懒加载控件
    private lazy var headImageView:UIImageView = {
        let imageView = UIImageView()
        imageView.layer.cornerRadius = 40
        imageView.layer.masksToBounds = true
        if let imageURL = HJUserAccountViewModel.shareAccount.account?.avatar_large {
            let url = NSURL(string: imageURL)
            imageView.sd_setHighlightedImageWithURL(url)
            imageView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "avatar_default_big"))
        }
        return imageView
    }()
    
    
    
    private lazy var messageLabel:UILabel = {
        let message = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 15)
        message.text = "欢迎回来"
        message.alpha = 0
        return message
    }()


}
